package com.rem.mp;

import com.rem.mp.mapper.UserMapper;
import com.rem.mp.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 逻辑删除
 * <p>
 * 开发系统时，有时候在实现功能时，删除操作需要实现逻辑删除，所谓逻辑删除就是将数据标记为删除，而并非真正
 * 的物理删除（非DELETE操作），查询时需要携带状态条件，确保被标记的数据不被查询到。这样做的目的就是避免
 * 数据被真正的删除。
 *
 * @Author Rem
 * @Date 2020-03-01
 */

@RunWith(SpringRunner.class)
@SpringBootTest
public class MyApplicationTest8 {

    @Autowired
    private UserMapper userMapper;

    /**
     * 逻辑删除
     * UPDATE tb_user SET deleted = 1 WHERE id = 5 AND deleted = 0
     */
    @Test
    public void testDel() {
        int del = userMapper.deleteById(5L);
        System.out.println(del);
    }

    /**
     * 测试查询
     * SELECT id, user_name, name, age, email AS mail, version, deleted FROM tb_user WHERE id = ? AND deleted = 0
     */
    @Test
    public void testSelect() {
        User user = userMapper.selectById(5L);
        System.out.println(user); //null
    }

}
